﻿//显示相册列表
function ShowAlbumInfo(albumID, showtype) {
    $("#hid_albumID").val(albumID);
    $("#ul_UserAlbumList li").attr("class", "");
    $("#ul_UserAlbumList li[albumID='" + albumID + "']").attr("class", "ac over");
    var tempHtml = managephoto_V2.getAlbumPhotos($("#hidUserID").val(), albumID, 1).value;
    if (tempHtml == "") {
        $(".imglist").html("<ul><li>暂无照片</li></ul>");
        $(".pager").html("");
    } else {
        $(".imglist").html(tempHtml.split("$pager$")[0]);

        if (tempHtml.split("$pager$")[1] == undefined) {
            $(".pager").html("");
        } else {
            $(".pager").html(tempHtml.split("$pager$")[1]);
        }
    }
    var albumInfoHtml = managephoto_V2.GetAlbumInfo(albumID).value;
    $("#div_albumInfo").html(albumInfoHtml);
    $("#hid_curPage").val(1);
    Ucenter.bImage.init();
    if (showtype == 2) {
        $('.cover dd .title').trigger('click');
    }
}
//显示相关相册下的图片信息
function GetAlbumPhotoList(albumID, curPage) {
    goto_top();
    $("#hid_albumID").val(albumID);
    var tempHtml = managephoto_V2.getAlbumPhotos($("#hidUserID").val(), albumID, curPage).value;
    $("#hid_curPage").val(curPage);
    if (tempHtml == "") {
        $(".imglist").html("<ul><li>暂无照片</li></ul>");
        $(".pager").html("");
    } else {
        $(".imglist").html(tempHtml.split("$pager$")[0]);
        if (tempHtml.split("$pager$")[1] == undefined) {
            $(".pager").html("");
        } else {
            $(".pager").html(tempHtml.split("$pager$")[1]);
        }
    }
    Ucenter.bImage.init();
}
//创建相册
function CreateAlbum() {
    var tempHtml = "<form id=\"my\"><div id=\"FloatDiv\"><table cellpadding=\"5\"><tr><td>请输入相册名称:<br><br><input type=\"text\" id=\"txtGroupName\" size=\"40\" name=\"txtGroupName\" style=\"border:1px solid #d2d2d2\" value=\"\"></td></tr><tr><td>请输入相册描述:<br><br><textarea id=\"txtGroupDesc\" cols=\"32\" rows=\"5\" name=\"txtGroupDesc\" style=\"border:1px solid #d2d2d2\"></textarea></td></tr></table></div></form>";
    art.dialog({
        title: "添加相册",
        content: tempHtml,
        skin: 'aero',
        yesFn: function () {
            var groupName = $.trim($("#txtGroupName").val());
            var groupDesc = $.trim($("#txtGroupDesc").val());
            var userID = $.trim($("#hidUserID").val());
            if (groupName == '' || groupName == '相册标题') {
                art.dialog.alert("请输入相册名称！");
                return false;
            }
            if (GetStringLength(groupName) > 40) {
                art.dialog.alert("相册名称最长20个汉字，40个英文字母！");
                return false;
            }
            var iRet = managephoto_V2.CreateAlbum(groupName, groupDesc, userID).value;
            if (iRet > 0) {
                //art.dialog.alert("相册创建成功，等待审核！");
                $("#ul_UserAlbumList").html(managephoto_V2.GetUserAlbumList($("#hidUserID").val()).value);
                Ucenter.bImage.init();
                Ucenter.init();
            } else {
                art.dialog.alert("相册创建失败！");
            }
        },
        width: 360,
        height: 200,
        noFn: true
    });

}

function selectAllImg() {
    $($("input[name='checkpicture']")).each(function (i) {
        $(this).attr("checked", !$(this).attr("checked"));
    });
}
function delAlbum(albumID, albumName, photoNum) {
    if (albumName != "我的相册" && albumName != "手机相册") {
        art.dialog({
            id: "delGroup",
            title: "删除相册",
            content: "相册删除后,该相册下的照片会自动移动到系统自动生成的相册‘我的相册’下，确定删除相册吗？",
            icon: 'confirm',
            focus: "delGroupyes",
            skin: 'aero',
            yesFn: function () {
                var iRet = 0;
                iRet = managephoto_V2.deleteAlbum(albumID, -1, 1).value;
                if (iRet == 0) {
                    art.dialog.alert("删除失败！");
                } else if (iRet > 0) {
                    //art.dialog.alert("删除成功！");
                    $("#ul_UserAlbumList").html(managephoto_V2.GetUserAlbumList($("#hidUserID").val()).value);
                    GetAlbumPhotoList(0, 1);
                    Ucenter.init();
                }
            },
            width: 200,
            height: 80,
            noFn: true
        });

    } else {
        art.dialog.alert("系统相册，不能删除");
    }
}
//移动相册
function movePhoto(albumId, newAlbumId, newAlbumName) {
    $('.imglist .vopera .move').blur();
    var flag = true;
    var iCount = $("input[type='checkbox'][name='checkpicture']:checked").length;
    if (iCount == 0) {
        art.dialog.alert("请先选择");
    }
    else {
        $($("input[name='checkpicture']")).each(function (i) {
            if ($(this).attr("checked")) {
                var imgID = $(this).val();

                var iRet = managephoto_V2.movePhotos(albumId, newAlbumId, imgID).value;
                if (iRet == 0) {
                    flag = false;
                }
                else if (iRet > 0) {
                    flag = true;
                }
            }
        });
    }
    if (flag == false) {
        art.dialog.alert("移动失败！");
    }
    else if (flag == true) {
        //art.dialog.alert("移动成功！");
        if ($("#hid_albumID").val == "0") {
            ShowAlbumInfo(newAlbumId);
            $("#ul_UserAlbumList li[albumID='" + newAlbumId + "']").attr("class", "ac over");
        }
        else {
            ShowAlbumInfo(albumId);
        }
    }
    Ucenter.bImage.init();
}
//删除图片
function delPhoto() {
    var flag = true;
    var iCount = $("input[type='checkbox'][name='checkpicture']:checked").length;
    if (iCount == 0) {
        art.dialog.alert("请先选择");
    }
    else {
        $($("input[name='checkpicture']")).each(function (i) {
            if ($(this).attr("checked")) {
                var imgID = $(this).val();
                var iRet = managephoto_V2.deletePhoto(imgID, albumID).value;
                if (iRet == 0) {
                    flag = false;
                } else if (iRet > 0) {
                    flag = true;
                }
            }
        });
    }
    if (flag == false) {
        art.dialog.alert("删除失败，请稍后再试！");
    }
    else if (flag == true) {
        art.dialog.alert("删除成功！");
        GetAlbumPhotoList($("#hid_albumID").val(), $("#hid_curPage").val());
    }
    Ucenter.bImage.init();
}
//设为封面
function setCover(albumID) {
    var iCount = $("input[type='checkbox'][name='checkpicture']:checked").length;
    if (iCount == 0) {
        art.dialog.alert("请先选择");
        return false;
    } else if (iCount > 1) {
        art.dialog.alert("只能选一个");
        return;
    }
    else {
        var imgID = $("input[type='checkbox'][name='checkpicture']:checked").val();
        var iRet = managephoto_V2.setCover(albumID, imgID).value;
        if (iRet == 0) {
            art.dialog.alert("设置失败，请稍候再试");
        } else if (iRet > 0) {
            //                                 alert("设置成功！");
            if ($("#hid_albumID").val() == albumID) {
                $("#div_albumInfo").html(managephoto_V2.GetAlbumInfo(albumID).value);
                GetAlbumPhotoList(albumID, $("#hid_curPage").val());
                art.dialog.alert("设置成功！");
            }
        }
    }
    Ucenter.bImage.init();
}
//投稿
function conChannels(channelID) {
    $('.imglist .vopera .tougao').blur();
    //$('.pic_cate_list').hide();
    var flag = true;
    var iCount = $("input[type='checkbox'][name='checkpicture']:checked").length;
    if (iCount == 0) {
        art.dialog.alert("请先选择");
    }
    else {
        $($("input[name='checkpicture']")).each(function (i) {
            if ($(this).attr("checked")) {
                var imgID = $(this).val();
                var cons = managephoto_V2.conChannel(channelID, imgID).value;
                if (cons <= 0) {
                    flag = false;
                }
            }
        });
    }
    if (flag == false) {
        art.dialog.alert("投稿失败，请稍后再试！");
    }
    else {
        //        art.dialog.alert("投稿成功！");
        GetAlbumPhotoList($("#hid_albumID").val(), $("#hid_curPage").val());
    }
    Ucenter.bImage.init();
}